<template>
  <el-select
    :multiple="select.multiple"
    :placeholder="select.placeholder"
    v-model="model"
  >
    <el-option
      :key="item[select.value]"
      :label="item[select.label]"
      :value="item[select.value]"
      v-for="item in options"
      v-loading="loading"
    >
    </el-option>
  </el-select>
</template>

<script>
import _ from "lodash";
import * as request from "@/axios/axios";

export default {
  name: "select_index",
  data() {
    return {
      options: [{}],
      loading: false
    };
  },
  created() {
    if (!_.isEmpty(this.select.url)) {
      this.loading = true;
      //加载数据
      request.post(this.select.url, this.select.params).then(response => {
        this.options = response.data;
        this.loading = false;
      });
    }
  },
  props: {
    select: {
      multiple: {
        type: Boolean,
        default: false
      },
      placeholder: {
        type: String,
        default: "请选择"
      },
      url: "",
      label: {
        type: String,
        default: "name"
      },
      value: {
        type: String,
        default: "id"
      }
    },
    model: Object,
    param: {}
  }
};
</script>

<style scoped></style>
